<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>管理员登录</title>
<link href="./style/authority/login_css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./scripts/jquery/jquery-1.7.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		
		$("#login_sub").click(function(){
			var adminName = document.getElementById("name").value;
			var password = document.getElementById("pwd").value;
			if(adminName==null || adminName=="" || password==null || password==""){
				alert("输入不能为空！");
				return;
			}
			$("#submitForm").attr("action", "/SSH2/adminLogin").submit();
		});
	});
	
	/*回车事件*/
	function EnterPress(e){ //传入 event 
		var e = e || window.event; 
		if(e.keyCode == 13){ 
			var adminName = document.getElementById("name").value;
			var password = document.getElementById("pwd").value;
			if(adminName==null || adminName=="" || password==null || password==""){
				alert("输入不能为空！");
				return;
			}
			$("#submitForm").attr("action", "/SSH2/adminLogin").submit();
		} 
	}
	
	function searchAdmin() {
		var adminName = document.getElementById("name").value;
		var password = document.getElementById("pwd").value;
		if(adminName != null && adminName !=""){
			console.log(adminName);
			//兼容性写法创建请求实例,IE5 6支持else里面的方法
			if (window.XMLHttpRequest){
				xmlhttp = new XMLHttpRequest();
			}else {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			//设置传送方式,地址,以及同步还是异步
			xmlhttp.open("GET","/SSH2/searchAdmin?adminName="+adminName,true);
			xmlhttp.onreadystatechange = callback;//状态改变的时候执行这个函数,用来判断是否请求完毕
			xmlhttp.send();//请求服务器
		}
	}
	
	function callback() {
		//请求完成表示
		if(xmlhttp.readyState ==4 && xmlhttp.status==200){
		if (xmlhttp.responseText){//根据数据库返回值来进行不同的显示
			var spanid = document.getElementById("result");
			result.innerHTML = xmlhttp.responseText;
		}
		}
	}
</script>
</head>
<body>
	<div id="login_center">
		<div id="login_area">
			<div id="login_box">
				<div id="login_form">
					<form id="submitForm" action="" method="post">
						<div><h2><a href="/SSH2/index">回到首页</a></h2></div>
						<div id="login_tip">
							<span id="login_err" class="sty_txt2"></span>
						</div>
						<div>
							 用户名：<input type="text" name="adminName" class="username" id="name" onblur="searchAdmin()">
						</div>
						<div style="color:red;padding-top:15px;">
							<span id="result"></span>
						</div>
						<div>
							密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type="password" name="password" class="pwd" id="pwd" onkeypress="EnterPress(event)" onkeydown="EnterPress()">
						</div>
						<div style="color:red;padding-top:15px;">
							<c:if test="${!empty requestScope.error }">
								${requestScope.error }
							</c:if>
						</div>
						<div id="btn_area">
							<input type="button" class="login_btn" id="login_sub"  value="登  录">
							<input type="reset" class="login_btn" id="login_ret" value="重 置">
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>
</body>
</html>
